package ru.michaeltyan.familyconnector.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import ru.michaeltyan.familyconnector.beans.Foodstuff;
import ru.michaeltyan.familyconnector.dao.FoodstuffDao;

public class FoodstuffDaoImpl extends HibernateDaoSupport implements FoodstuffDao {

	public void save(Foodstuff foodstuff) {
		getHibernateTemplate().save(foodstuff);
	}

	public void update(Foodstuff foodstuff) {
		getHibernateTemplate().update(foodstuff);

	}

	public void delete(Foodstuff foodstuff) {
		getHibernateTemplate().delete(foodstuff);

	}

	public Foodstuff findByName(String foodstuffName) {
		@SuppressWarnings("rawtypes")
		List foodstuffs = getHibernateTemplate().find("from Foodstuff where foodstuffName=?", foodstuffName);
		if (foodstuffs != null && foodstuffs.size() > 0) {
			return (Foodstuff) foodstuffs.get(0);
		} else {
			return null;
		}
	}

}
